/**
 * 自动引入模板，在原有 sw-precache 插件默认模板基础上做的二次开发
 *
 * 因为是自定导入的模板，项目一旦生成，不支持随 sw-precache 的版本自动升级。
 * 可以到 Lavas 官网下载 basic 模板内获取最新模板进行替换
 *
 */

/* eslint-disable */

'use strict';

var precacheConfig = [["/2023/04/27/测试文章/94840836_p0.jpg","12ff690ba45da19f4da7a1b7185370bd"],["/2023/04/27/测试文章/index.html","1d4b4ed423f4810dd1b8129d664b9ddc"],["/2023/04/28/Java/index.html","9f92e11368df5570eeada0d12d1a1ff2"],["/2023/04/29/Mermaid画图测试/index.html","7f2367f2a47ab1d902eed2fad7c2e95a"],["/2023/04/30/hexo的部署及SSL应用/index.html","aa212ec179b1db537249423af4b89e78"],["/2023/05/02/javafx使用maven打包及运行/index.html","46fa29d50a60be90c09f1f8f15704423"],["/2023/05/02/安利几个好用的网站/index.html","2034dc001bbba2f4610ca14faac145f6"],["/2023/05/02/运算符级别比较/index.html","f078ce33cec674ac1356d6b0d9c1b511"],["/2023/05/02/集合-Map/index.html","a4472ddee65ec8f871f1d7e25c41ec9c"],["/2023/05/06/记一次电脑启动原神蓝屏解决方案/index.html","8214bbc31501e46f0f331da4a5c66f11"],["/2023/05/08/frp之内网穿透/index.html","32512435386fe276e772057275f01c8e"],["/2023/05/14/集合类的继承及实现概览/index.html","72e15d7e5b7269f8077017fc2a257cad"],["/2023/06/13/湖北飞young算号器/index.html","549293b09f9ba4c1b8c1632daeb3c565"],["/2023/06/17/windows之重装系统/index.html","f96b10c9fd082052d06907d11fae62f4"],["/2023/06/28/记一次打暑假工的经历/index.html","341ee35eb04688184a336fa6dddce112"],["/2023/07/08/maven的使用/index.html","be5588910094dd784626618fdf5b637f"],["/2023/07/11/Java-lambda的方法引用/index.html","3d71c0efe3a20c52783bcb9a826e3145"],["/2023/09/04/Docker部署/index.html","45c81ae7d181981466641d55dcb5257d"],["/2023/09/05/Docker的使用-壹/index.html","1183359725dcf87438ef5e66e53bb59a"],["/2023/09/05/docker的使用-贰/index.html","632dd3933adf39197c7a98c265568097"],["/2023/09/08/Docker的使用-叁/index.html","1655283b2817346b1a8ba927a0e48090"],["/2023/09/08/shell脚本笔记/index.html","dc1fadcfc39198c584639d9d993efad9"],["/2023/09/08/可道云桌面搭建笔记/index.html","24af12fe5263887dc8b54eb73e0267b6"],["/2023/09/09/Win至Linux的免密登录/index.html","86150ee4cfbcebe5ba530e0eead3e285"],["/2023/09/11/Docker构建镜像及使用的笔记/index.html","4da1fcaf339719450af6146b06552c2b"],["/2023/09/12/Docker之nginx的负载均衡/index.html","2847ea6843cb99ac0e8cf899148ef61f"],["/2023/09/12/harbor本地仓库搭建/index.html","95fa56d36628ce31fbbf474e62863d1c"],["/2023/09/15/Linux2023-9-15作业/index.html","37154aca91f9bb5fd0cdd67fa76bd3a4"],["/2023/09/16/谈谈看完《孤注一掷》的感想/index.html","febd8b619efcc70f71c343c8bafaa9e8"],["/2023/09/18/Linux2023-9-18作业/index.html","1c75f563e1266cdd6c6875e4e40baefe"],["/2023/09/26/使用cAdvisor-Prometheus-Grafana监控Docker容器/index.html","0767ca580c7d1602957b26b83fc4c648"],["/404.html","8e0c1631b455faf7f4f80fe6c69cc42f"],["/about/index.html","b3d6658c4b603aee822caeb9bcecdd85"],["/about/site.html","13ab5cc8a4edf3766814ac5518a4ded0"],["/albums/Test.html","a970bf5b1c118874a3629a457650a3a5"],["/albums/Test/test.jpg","12ff690ba45da19f4da7a1b7185370bd"],["/albums/index.html","e0d9091c484bf651e97dadd39d70154f"],["/albums/sunset.html","cb4c054e15287bd1ca5f7c1814f1e22f"],["/albums/sunset/bj.jpg","67d19c5755f7179b1e3b3ad7913c8b48"],["/albums/壁纸.html","3b907255304da38ee6e523edf1982be1"],["/albums/日常.html","8fab30655711a8e832a0af8a6fd38a30"],["/albums/日常/1.jpg","1e41ecb0d387116e5069c9ea845b79ad"],["/albums/日常/10.jpg","c9d778caa2b4da32023f6c662a7341e0"],["/albums/日常/11.jpg","78229164de1ada543d947e3bc0f2ac77"],["/albums/日常/12.jpg","dfc6dd055bf9c863ebe37995ee6f165d"],["/albums/日常/2.jpg","bfe3f4feeefa4c7c3f0542a4e51014c2"],["/albums/日常/3.jpg","7a7de05ffdeab7066e098bea196feb64"],["/albums/日常/4.jpg","b3e9650190e500e024f91d310670aae6"],["/albums/日常/5.jpg","4e4037f3e52ed3732f36db2d38e062dc"],["/albums/日常/6.jpg","12d7edd39472635d6522f7bf1342496d"],["/albums/日常/7.jpg","39f54f481bf10c92bb125abce1aef23c"],["/albums/日常/8.jpg","2abcc2e690e127d6889eb713a26c924a"],["/albums/日常/9.jpg","8601f302e984dd2f52cc3e57d4d017a8"],["/archives/2023/04/index.html","1459b5c8aa35444825e39142d4dda8ff"],["/archives/2023/05/index.html","86a05e079ad5b50f35691d5a6e1ee953"],["/archives/2023/06/index.html","dc65d751a1bd1fbd88f0d27a37bfa52a"],["/archives/2023/07/index.html","11e068e99ce7ea5f3afc4b7c4a160ec3"],["/archives/2023/09/index.html","260231f737d86cd389ad60deec021773"],["/archives/2023/09/page/2/index.html","8aa83989da44a964d07084993f15bdc2"],["/archives/2023/index.html","6da42fce22532e0466886b4a1635dc39"],["/archives/2023/page/2/index.html","35ced79049f03418df67c27bac4c79c7"],["/archives/2023/page/3/index.html","3b5928a2aa8760e82f2b057b5828f42d"],["/archives/index.html","f41bffa35ed7c31f1b11736925996a90"],["/archives/page/2/index.html","8ec2ed2b452a49f7842787377fcdbef4"],["/archives/page/3/index.html","17664cb55c465eb9aef9652a59f1a528"],["/categories/index.html","5d24c334c6acdd5bd99a4572a0b94c76"],["/categories/安利/index.html","87fb9ed925d935e03a4a3a5c181eb3d8"],["/categories/日记/index.html","d370774a14e8a8c09e29add8a5da7202"],["/categories/笔记/index.html","f8e10bc145e41683a9e3c0fdae9adf5b"],["/categories/编程技巧/index.html","0f0446cb4567dd4b04cdb2003e3d67c4"],["/categories/编程技巧/page/2/index.html","f6ea6349390ffeb3eeb1d28ff8d41513"],["/categories/计算机知识/index.html","8e1a58b4f5e69cef538152f7e8f361be"],["/css/README.html","5b0fdfbf117addbdb14fc3c03d2d3a34"],["/css/hexo-theme-yun.css","ac3db65cefda1502a1b4773b026285ab"],["/images/abj.jpg","67d19c5755f7179b1e3b3ad7913c8b48"],["/images/bjb.jpg","69ff4607e07e344c8f53194838cd295c"],["/images/docker的使用-壹/1.png","46e744abf9d04cc4ee0ec7b542c7fb30"],["/images/docker的使用-壹/2.png","4c8df07a0f7d9579752463ae90108f01"],["/images/docker的使用-壹/3.png","30979d93d56e2b8abf8a33b145e9043e"],["/images/docker的使用-贰/1.png","785a089c95abe0f9ade56b1483c18d0f"],["/images/docker的使用-贰/2-3.png","3ec82ff3f55ca4c477b37f1b13ec07a1"],["/images/docker的使用-贰/4.png","fa925e57931e2f1a4f0633003b958cf0"],["/images/docker的使用-贰/5.png","0285d962b6a687fc2de2174b7a69cb21"],["/images/icon120.png","66823855111ab5a4c35867a54638128f"],["/images/l7.png","6685493823b76c2b57c7583f2dbc6695"],["/images/l8.png","e2e9f9e471abf410028f0835f6fe35fc"],["/images/test.jpg","12ff690ba45da19f4da7a1b7185370bd"],["/images/wa.jpg","41180250240fe331cfc645da15514b15"],["/index.html","ee0fe95d4991a4cbf50526d9783d7702"],["/js/analytics/leancloud-visitors.js","3b07f687dce2d7a08cccaf552fdf42a0"],["/js/chunk-72ZP56JR.js","057276d9c9cb6224881dde190c6dbd9f"],["/js/chunk-FEIY7W7S.js","3ef93ccfbbc95d8c64ba9e38752ba428"],["/js/comments/disqus.js","25830e4f1bc3bdd7916a60a73d5168a5"],["/js/comments/waline.js","c8671037215325e6afafef942a8fdee8"],["/js/gallery-decrypt.js","b28b80cb444e87389a4c2f7c9ba00d8a"],["/js/hexo-theme-yun.js","210be2b5da5325a841812a61b1d6fb19"],["/js/pjax.js","978feafed4ef06c273a152b4d432ade4"],["/js/say.js","f642a189ce86e6296d783b1f7898d88c"],["/js/search/algolia-search.js","e9e37b68607e170a7bb8bcf80750dce3"],["/js/search/local-search.js","28ab7bcf447654361241094af1178d10"],["/js/sidebar.js","072a46a4cbc6d3c2f01229741193f23e"],["/js/ui/banner.js","ebf08467f6408d982f69dcbeecbe8267"],["/js/ui/fireworks.js","5aac30979e637959c5a4486a4b902e7d"],["/js/utils.js","955c85adc7bd32dd906ee39c5b730498"],["/links/index.html","855ec5c9fdf2edbfe748185dccca3bf2"],["/page/2/index.html","48ce832a95b54ea382256e5c5473e549"],["/page/3/index.html","de634bccb9082538ace1cfb584e38c1e"],["/sw-register.js","8eface490956ed9a9bb2cffa0167b534"],["/tags/Docker/index.html","72874acb34e7b4465705153324568573"],["/tags/Grafana/index.html","9e0df43c1d014142e5807f7fe5f6241d"],["/tags/Linux/index.html","643195f388386e1c62785af0ae9f1698"],["/tags/Prometheus/index.html","1ee0f137546cd4b6b03225a99f2cd8a6"],["/tags/SSH/index.html","1a54afe58db096522d47ee9199b78a30"],["/tags/cAdvisor/index.html","2fa31861821d3b4fb272639a4ece0c19"],["/tags/frp/index.html","05d0f4b874c85395c71b87bfad767cdd"],["/tags/harbor/index.html","d4e5ff02ebe70c273a8ba2b9214d0227"],["/tags/hexo/index.html","8ea895892e93f1c18b50cdb1e4994299"],["/tags/index.html","a1489e3b071c6603c468645e750cabdd"],["/tags/java/index.html","a7d6c896bddedf6817757b11fc1ccde8"],["/tags/javafx/index.html","9c2cf719d8346cabcfb73646cb82e800"],["/tags/java线程/index.html","8225830be49785cddf90854a393a3f0c"],["/tags/lambda表达式/index.html","1e54c6e587550c3244ad0b3f0d69c3f3"],["/tags/markdown/index.html","9b83b9e01f83a252e27e7f62f09bcac4"],["/tags/maven/index.html","fcd9a8990e288a1b6c855c9358932e94"],["/tags/mermaid/index.html","29393784ad69d6d8a222632da62b6986"],["/tags/shell/index.html","d8fa947b8f530147b6a99db163bc5d6b"],["/tags/分享/index.html","7a0ec9e48b535f9cb3f8f7861ffb0d2d"],["/tags/原创/index.html","b0e7bc6b7e306b29d6442d9bbbcc43f1"],["/tags/原创/page/2/index.html","259b6c7efba5d1c88aa22669db092dde"],["/tags/原创/page/3/index.html","af0b3049539d416aaa8f49aa87857baa"],["/tags/可道云/index.html","030661f3f6b9d19d6b418f0d9a8a53c3"],["/tags/暑假工/index.html","0b9381a0958dbef6379aea71da1af93e"],["/tags/电脑技术/index.html","f22f67a569b75b76ffe5f0600f61809d"],["/tags/破解/index.html","74b4edab548b2b969422709b1b6447ad"],["/tags/计算机/index.html","b29d2c741d98b6e9c7506f293ea6691d"],["/tags/记录/index.html","23be744aba90a024c0be596b74e47199"],["/tags/集合/index.html","2d62631691e17c3b8e2381d85a3360b8"],["/wztb.png","c7827658dd2eee50653b6cfa5ee982dd"],["/yun.png","2c82d6847fdad2661d89b47af441cc45"],["/yun.svg","d857d9e35dbb588e4e80d4966e7f2d1c"]];
var cacheName = 'sw-precache-v3--' + (self.registration ? self.registration.scope : '');
var firstRegister = 1; // 默认1是首次安装SW， 0是SW更新


var ignoreUrlParametersMatching = [/^utm_/];


var addDirectoryIndex = function (originalUrl, index) {
    var url = new URL(originalUrl);
    if (url.pathname.slice(-1) === '/') {
        url.pathname += index;
    }
    return url.toString();
};

var cleanResponse = function (originalResponse) {
    // 如果没有重定向响应，不需干啥
    if (!originalResponse.redirected) {
        return Promise.resolve(originalResponse);
    }

    // Firefox 50 及以下不知处 Response.body 流, 所以我们需要读取整个body以blob形式返回。
    var bodyPromise = 'body' in originalResponse ?
        Promise.resolve(originalResponse.body) :
        originalResponse.blob();

    return bodyPromise.then(function (body) {
        // new Response() 可同时支持 stream or Blob.
        return new Response(body, {
            headers: originalResponse.headers,
            status: originalResponse.status,
            statusText: originalResponse.statusText
        });
    });
};

var createCacheKey = function (originalUrl, paramName, paramValue,
    dontCacheBustUrlsMatching) {

    // 创建一个新的URL对象，避免影响原始URL
    var url = new URL(originalUrl);

    // 如果 dontCacheBustUrlsMatching 值没有设置，或是没有匹配到，将值拼接到url.serach后
    if (!dontCacheBustUrlsMatching ||
        !(url.pathname.match(dontCacheBustUrlsMatching))) {
        url.search += (url.search ? '&' : '') +
            encodeURIComponent(paramName) + '=' + encodeURIComponent(paramValue);
    }

    return url.toString();
};

var isPathWhitelisted = function (whitelist, absoluteUrlString) {
    // 如果 whitelist 是空数组，则认为全部都在白名单内
    if (whitelist.length === 0) {
        return true;
    }

    // 否则逐个匹配正则匹配并返回
    var path = (new URL(absoluteUrlString)).pathname;
    return whitelist.some(function (whitelistedPathRegex) {
        return path.match(whitelistedPathRegex);
    });
};

var stripIgnoredUrlParameters = function (originalUrl,
    ignoreUrlParametersMatching) {
    var url = new URL(originalUrl);
    // 移除 hash; 查看 https://github.com/GoogleChrome/sw-precache/issues/290
    url.hash = '';

    url.search = url.search.slice(1) // 是否包含 '?'
        .split('&') // 分割成数组 'key=value' 的形式
        .map(function (kv) {
            return kv.split('='); // 分割每个 'key=value' 字符串成 [key, value] 形式
        })
        .filter(function (kv) {
            return ignoreUrlParametersMatching.every(function (ignoredRegex) {
                return !ignoredRegex.test(kv[0]); // 如果 key 没有匹配到任何忽略参数正则，就 Return true
            });
        })
        .map(function (kv) {
            return kv.join('='); // 重新把 [key, value] 格式转换为 'key=value' 字符串
        })
        .join('&'); // 将所有参数 'key=value' 以 '&' 拼接

    return url.toString();
};


var addDirectoryIndex = function (originalUrl, index) {
    var url = new URL(originalUrl);
    if (url.pathname.slice(-1) === '/') {
        url.pathname += index;
    }
    return url.toString();
};

var hashParamName = '_sw-precache';
var urlsToCacheKeys = new Map(
    precacheConfig.map(function (item) {
        var relativeUrl = item[0];
        var hash = item[1];
        var absoluteUrl = new URL(relativeUrl, self.location);
        var cacheKey = createCacheKey(absoluteUrl, hashParamName, hash, false);
        return [absoluteUrl.toString(), cacheKey];
    })
);

function setOfCachedUrls(cache) {
    return cache.keys().then(function (requests) {
        // 如果原cacheName中没有缓存任何收，就默认是首次安装，否则认为是SW更新
        if (requests && requests.length > 0) {
            firstRegister = 0; // SW更新
        }
        return requests.map(function (request) {
            return request.url;
        });
    }).then(function (urls) {
        return new Set(urls);
    });
}

self.addEventListener('install', function (event) {
    event.waitUntil(
        caches.open(cacheName).then(function (cache) {
            return setOfCachedUrls(cache).then(function (cachedUrls) {
                return Promise.all(
                    Array.from(urlsToCacheKeys.values()).map(function (cacheKey) {
                        // 如果缓存中没有匹配到cacheKey，添加进去
                        if (!cachedUrls.has(cacheKey)) {
                            var request = new Request(cacheKey, { credentials: 'same-origin' });
                            return fetch(request).then(function (response) {
                                // 只要返回200才能继续，否则直接抛错
                                if (!response.ok) {
                                    throw new Error('Request for ' + cacheKey + ' returned a ' +
                                        'response with status ' + response.status);
                                }

                                return cleanResponse(response).then(function (responseToCache) {
                                    return cache.put(cacheKey, responseToCache);
                                });
                            });
                        }
                    })
                );
            });
        })
            .then(function () {
            
            // 强制 SW 状态 installing -> activate
            return self.skipWaiting();
            
        })
    );
});

self.addEventListener('activate', function (event) {
    var setOfExpectedUrls = new Set(urlsToCacheKeys.values());

    event.waitUntil(
        caches.open(cacheName).then(function (cache) {
            return cache.keys().then(function (existingRequests) {
                return Promise.all(
                    existingRequests.map(function (existingRequest) {
                        // 删除原缓存中相同键值内容
                        if (!setOfExpectedUrls.has(existingRequest.url)) {
                            return cache.delete(existingRequest);
                        }
                    })
                );
            });
        }).then(function () {
            
            return self.clients.claim();
            
        }).then(function () {
                // 如果是首次安装 SW 时, 不发送更新消息（是否是首次安装，通过指定cacheName 中是否有缓存信息判断）
                // 如果不是首次安装，则是内容有更新，需要通知页面重载更新
                if (!firstRegister) {
                    return self.clients.matchAll()
                        .then(function (clients) {
                            if (clients && clients.length) {
                                clients.forEach(function (client) {
                                    client.postMessage('sw.update');
                                })
                            }
                        })
                }
            })
    );
});



    self.addEventListener('fetch', function (event) {
        if (event.request.method === 'GET') {

            // 是否应该 event.respondWith()，需要我们逐步的判断
            // 而且也方便了后期做特殊的特殊
            var shouldRespond;


            // 首先去除已配置的忽略参数及hash
            // 查看缓存简直中是否包含该请求，包含就将shouldRespond 设为true
            var url = stripIgnoredUrlParameters(event.request.url, ignoreUrlParametersMatching);
            shouldRespond = urlsToCacheKeys.has(url);

            // 如果 shouldRespond 是 false, 我们在url后默认增加 'index.html'
            // (或者是你在配置文件中自行配置的 directoryIndex 参数值)，继续查找缓存列表
            var directoryIndex = 'index.html';
            if (!shouldRespond && directoryIndex) {
                url = addDirectoryIndex(url, directoryIndex);
                shouldRespond = urlsToCacheKeys.has(url);
            }

            // 如果 shouldRespond 仍是 false，检查是否是navigation
            // request， 如果是的话，判断是否能与 navigateFallbackWhitelist 正则列表匹配
            var navigateFallback = '';
            if (!shouldRespond &&
                navigateFallback &&
                (event.request.mode === 'navigate') &&
                isPathWhitelisted([], event.request.url)
            ) {
                url = new URL(navigateFallback, self.location).toString();
                shouldRespond = urlsToCacheKeys.has(url);
            }

            // 如果 shouldRespond 被置为 true
            // 则 event.respondWith()匹配缓存返回结果，匹配不成就直接请求.
            if (shouldRespond) {
                event.respondWith(
                    caches.open(cacheName).then(function (cache) {
                        return cache.match(urlsToCacheKeys.get(url)).then(function (response) {
                            if (response) {
                                return response;
                            }
                            throw Error('The cached response that was expected is missing.');
                        });
                    }).catch(function (e) {
                        // 如果捕获到异常错误，直接返回 fetch() 请求资源
                        console.warn('Couldn\'t serve response for "%s" from cache: %O', event.request.url, e);
                        return fetch(event.request);
                    })
                );
            }
        }
    });









/* eslint-enable */
